package com.demo.goodsinfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/goodsinfo/")
public class GoodsInfoController {
	
	@Autowired
	GoodsInfoService goodsInfoServiceImpl;
	
	@RequestMapping(value = "search")
	@ResponseBody
	public Map<String, Object> search(HttpServletRequest request, HttpServletResponse response){
		String searchText = request.getParameter("searchText");
		int start = 0;
		try {
			start = Integer.parseInt(request.getParameter("start"));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		
		int limit = 10;
		try {
			limit = Integer.parseInt(request.getParameter("limit"));
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return goodsInfoServiceImpl.search(searchText, start, limit);
	}

}
